package net.openl10n.adapters;

import java.util.LinkedList;

public class EventPool implements ObjectPool<CachedEvent>{

	private LinkedList<CachedEvent> pool = new LinkedList<CachedEvent>();
	private final int maxedCached; 
	
	public EventPool(int maxedCached) {
		this.maxedCached = maxedCached; 
	}
	
	public EventPool() {
		this.maxedCached = Integer.MAX_VALUE;
	}
	
	@Override
	public void release(CachedEvent event) {
		if(pool.size() >= maxedCached)
			return;
		
		event.reset();
		pool.push(event);
	}

	@Override
	public CachedEvent take() {
		if(pool.isEmpty()){
			return new CachedEvent();
		}
		return pool.pop();
	}
}
